import asyncio
import time

async def sum(number: int):
    sum = 0
    await asyncio.sleep(number / 2)
    for i in range(number):
        sum += i

    return sum

async def total(): 
    task_list = []
    for j in range(6, 9):
        task_list.append(asyncio.create_task(sum(j), name=j))

    start = time.time()
    # 完成的任务写入done中，未完成写入pending
    done, pending = await asyncio.wait(task_list, timeout=10)
    end = time.time()
    print(done, pending)
    print("耗时:", end - start)
    return done, pending

if __name__ == '__main__':
    start = time.time()
    done, pendding = asyncio.run(total())
    print('==========')
    
    for d in done:
        print(d.result())
        
    end = time.time()
    print(end - start)